﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MMOArpgServer.DAL
{
    public class AccountCachePool : AbsCachePool
    {
        private Dictionary<int, string> _AccountNamePool = new Dictionary<int, string>();

        public override void AddCacheToPool(object key, AbsCacheData cache)
        {
            Console.WriteLine(key.ToString());
            string account = key.ToString();
            int id = (cache as AccountDBData).AccountID;
            _AccountNamePool.Add(id, account);
            base.AddCacheToPool(key, cache);
        }

        public override AbsCacheData GetCacheByKey(object key)
        {
            AbsCacheData temp = base.GetCacheByKey(key);
            return temp;
        }
        public override object GetKeyByCache(AbsCacheData cache)
        {
            return base.GetKeyByCache(cache);
        }
        public override void RemoveCache(object key)
        {
            base.RemoveCache(key);
        }
        public AccountDBData GetCahceByAccountID(int id)
        {
            string key;
            AccountDBData acc = null;
            if (id != -1)
            {
                key = _AccountNamePool[id];
                acc = _CachePool[key] as AccountDBData;
            }
            return acc;
        }
        public override void Release()
        {
            base.Release();
        }
        public AccountDBData GetFreeCache() {

            AccountDBData data = base.GetFreeCache() as AccountDBData;
            if (data == null) {
                data = new AccountDBData();
            }
            return data;
        }
    }
}
